﻿<?php 
      echo $this->Html->css("chosen");
      echo $this->Html->css("dataTables");
      echo $this->Html->css("validationEngine.jquery");
 ?>
<script type="text/javascript" src="<?php echo $this->webroot; ?>js/dataTables.min.js"></script>
<script type="text/javascript" src="<?php echo $this->webroot; ?>js/customInput.jquery.js"></script>
<script type="text/javascript" src="<?php echo $this->webroot; ?>js/chosen.js"></script>
<script type="text/javascript" src="<?php echo $this->webroot; ?>js/zice.custom1.js"></script>
<script type="text/javascript" src="<?php echo $this->webroot; ?>js/ColVis.js"></script>
<script type="text/javascript" src="<?php echo $this->webroot; ?>js/accounting.js"></script>
<script type="text/javascript" src="<?php echo $this->webroot; ?>js/layout_table.js"></script>
<script type="text/javascript" src="<?php echo $this->webroot; ?>js/manager_transfer_invoice.js"></script>
<script type="text/javascript" src="<?php echo $this->webroot; ?>js/jquery.validationEngine.js"></script>
<script type="text/javascript" src="<?php echo $this->webroot; ?>js/jquery.validationEngine-vi.js"></script>
<script type="text/javascript" src="<?php echo $this->webroot; ?>js/jquery.autotab.js"></script>
<div id="infoInvoiceRight">
	<h5><?php foreach ($invoice_info as $item) {echo date('d/m/Y H:i',strtotime($item['wh']['time'])); }?><h5>
	<h5>Code: <?php echo $invoice_code ?><h5>
</div>
<div style="float: left; width: 100%;">
<form id="validation">
	<div class="tableName">
		<?php if ($invoice_type == 'delivery'){ 
			echo "<table class='display data_table2 listProductDeInvoice' >
					<thead>
						<tr>
							<th><div class='th_wrapp'>Tên</div></th>
							<th><div class='th_wrapp'>Địa chỉ</div></th>
							<th><div class='th_wrapp'>Điện thoại</div></th>
							<th><div class='th_wrapp'>Tổng tiền</div></th>
							<th><div class='th_wrapp'>Ngày mua</div></th>
						</tr>
					</thead>
					<tbody>";
			foreach ($invoice_list_info as $item)
			{
				echo "<tr class='odd gradeX' id='".$item['de']['id']."'>";
				echo "<td >".$item['c']['name']."</td>";
				echo "<td>".$item['c']['address']."</td>";
				echo "<td>".$item['c']['phone']."</td>";
				echo "<td class='formatMoney'>".$item['wh']['total']."</td>";
				echo "<td>".date('d/m/Y H:i',strtotime($item['wh']['date']))."</td>";
				echo "</tr>";
				echo "<tr class='rowHeaderP'>
						<td><div></div></th>
						<td><div>Tên sản phẩm</div></td>
						<td><div>Quy cách</div></td>
						<td><div>Số lượng</div></td>
						<td><div>Thành tiền</div></td>
					</tr>";
				foreach ($invoice_list_detail as $item1)
				{
					if ( $item1['iv']['wholesale_invoice_id'] == $item['wh']['id']){
						echo "<tr class='rowDataP'>";
						echo "<td></td>";
						echo "<td>".$item1['p']['name']."</td>";
						echo "<td>".$item1['u']['unit']."</td>";
						echo "<td>".$item1['iv']['quantity']."</td>";
						echo "<td class='formatMoney'>".$item1['iv']['quantity']*$item1['iv']['cost']."</td>";
						echo "</tr>";
					}
				}
				foreach ($invoice_list_pro_detail as $item1)
				{
					if ( $item1['iv']['wholesale_invoice_id'] == $item['wh']['id']){
						echo "<tr class='rowDataP'>";
						echo "<td></td>";
						echo "<td>".$item1['p']['name']." (KM)</td>";
						echo "<td>".$item1['u']['unit']."</td>";
						echo "<td>".$item1['iv']['quantity']."</td>";
						echo "<td>0 đ</td>";
						echo "</tr>";
					}
				}
			}
			echo "</tbody></table>";
		} else {?>
		<table class="display data_table2" style="empty-cells: hide">
			<thead>
				<tr>
					<th><div class="th_wrapp">STT</div></th>
					<th><div class="th_wrapp">Tên sản phẩm</div></th>
					<th><div class="th_wrapp">Quy cách</div></th>
					<th><div class="th_wrapp">Số lượng</div></th>
					<th><div class="th_wrapp">Giá</div></th>
					<th><div class="th_wrapp">Thành tiền</div></th>
				</tr>
			</thead>
			<tbody>
			<?php 
				$index = 1;
				foreach ($invoice_list_info as $item) {
			?>
			<tr class="odd gradeX editC" >
      			<td><?php  echo $index; ?></td>
				<td><?php  echo $item['p']['name'];?></td>
				<td><?php  echo $item['u']['unit'];?></td>
				<td><?php  echo $item['iv']['quantity'];?></td>
				<td class='formatMoney'><?php  echo $item['iv']['cost'];?></td>
				<td class='formatMoney'><?php  echo $item['iv']['quantity']*$item['iv']['cost'];?></td>
      		</tr><?php $index++; }?>
			<?php if ($invoice_type == 'wholesale' ) { ?>
				<?php
					foreach ($invoice_list_pro_info as $item) {
				?>
				<tr class="odd gradeX editC" >
	      			<td><?php  echo $index; ?></td>
					<td><?php  echo $item['p']['name'];?> (KM)</td>
					<td><?php  echo $item['u']['unit'];?></td>
					<td><?php  echo $item['iv']['quantity'];?></td>
					<td class='formatMoney'>0 đ</td>
					<td class='formatMoney'>0 đ</td>
	      		</tr><?php $index++; }?>
	      		<tr>
					<td colspan="4"></td>
					<td>Tổng cộng: </td>
					<td><h5 class='formatMoney'><?php foreach ($invoice_info as $item) {echo $item['wh']['total']; }?></h5></td>
				</tr>
				<tr>
					<td colspan="4"></td>
					<td>Số thu: </td>
					<td><h5 class='formatMoney'><?php foreach ($invoice_info as $item) {echo $item['wh']['total'] - $item['wh']['own']; }?></h5></td>
				</tr>
				<tr>
					<td colspan="4"></td>
					<td>Còn nợ: </td>
					<td><h5 class='formatMoney'><?php foreach ($invoice_info as $item) {echo $item['wh']['own']; }?></h5></td>
				</tr>
			<?php } else{?>
				<tr>
					<td colspan="4"></td>
					<td>Tổng cộng: </td>
					<td><h5 class='formatMoney'><?php foreach ($invoice_info as $item) {echo $item['wh']['total']; }?></h5></td>
				</tr>
			<?php } ?>
			</tbody>
		</table>
		<?php }?>
    </div>
</form>
</div>